package com.pdg.mcplugin.spawnsurance.commandprocessors;

import org.bukkit.command.CommandSender;

import com.pdg.mcplugin.common.ArgumentList;
import com.pdg.mcplugin.common.baseclasses.CommandProcessorBase;
import com.pdg.mcplugin.spawnsurance.SpawnSurance;

public class SetClaimsForCommandProcessor extends
		CommandProcessorBase<SpawnSurance> {

	private static final String messageSuccess = "Claims for '%s' set to '%d'.";

	public SetClaimsForCommandProcessor(SpawnSurance thePlugin) {
		super(thePlugin, new String[]{
				"/spawnsurance set claims-for (player name) (number) - sets the claims for a particular player (not the current player)"
		});
	}

	@Override
	protected boolean specialProcessCommand(CommandSender theCommandSender,
			String theSubCommand, ArgumentList theArgumentList) {
		if(!getPlugin().getPermissionChecker().checkPermission(theCommandSender, Property.CLAIMS_FOR.getSetPermission())){
			return false;
		}
		try{
			String thePlayerName = theSubCommand;
			Integer theClaims = Integer.parseInt(theArgumentList.pop());
			getPlugin().getDataProvider().setPlayerClaims(thePlayerName, theClaims);
			getPlugin().sendSuccessMessage(theCommandSender, String.format(messageSuccess,thePlayerName,theClaims));
			return true;
		}catch(Exception e){
			getPlugin().getLogger().severe(e.getMessage());
			return false;
			
		}
	}

}
